package com.cn.stringBuilder;

/**
 * 3. StringBuilder和String相互转换
 *
 * 3.1 StringBuilder转换为String
 * public String toString()：通过 toString() 就可以实现把 StringBuilder 转换为 String
 *
 * 3.2 String转换为StringBuilder
 * public StringBuilder(String s)：通过构造方法就可以实现把 String 转换为 StringBuilder
 *
 */
public class StringBuilder_03_ConvertString {
    public static void main(String[] args) {
        //stringBuilderConvertToString();
        //stringConvertToStringBuilder();
    }

    /**
     * StringBuilder 转换成String
     */
    private static void stringBuilderConvertToString() {
        //StringBuilder 转换为String
        StringBuilder sb = new StringBuilder();
        sb.append("hello");
        //public String toString()：通过 toString() 就可以实现把 StringBuilder 转换为 String
        String s = sb.toString();
        System.out.println(s);
    }

    /**
     * String 转换成 StringBuilder
     */
    private static void stringConvertToStringBuilder() {
        String s = "hello";
        //public StringBuilder(String s)：通过构造方法就可以实现把 String 转换为 StringBuilder
        StringBuilder sb = new StringBuilder(s);
        System.out.println(sb);
    }


}
